<template>
  <div class="set" v-loading="loading">
    <el-card class="box-card">
      <div slot="header" class="header">
        <span>原文存储路径设置</span>
        <div>
          <!--<el-button size="small" icon="el-icon-edit">编辑</el-button>-->
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading1"
                     @click="handleSave(1)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="ywData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="根路径：" prop="root">
            <el-input size="small" disabled v-model="ywData.rootPath"></el-input>
            <!--            <el-button size="small">检验</el-button>-->
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="ywData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="子路径：">
            <el-input disabled size="small" v-model="ywData.subPath"></el-input>
            <el-button size="small" @click="handleChange('1')">选择</el-button>
            <div class="tips">
                <span v-for="(item, index) in ywSrcFormat"
                      :key="index">
                    {{index !== 0 ? '/' : ''}}{{item.dictLabel}}{{'-' + item.length}}
                </span>
            </div>
          </el-form-item>
          <el-form-item label="原文存储方式：" prop="name">
            <el-radio-group v-model="ywData.saveMode">
              <el-radio :label="'1'">默认文件名</el-radio>
              <el-radio :label="'2'">档号+页码</el-radio>
              <el-radio :label="'3'">页码</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="页码位数：" v-if="ywData.saveMode>1">
            <div class="page-num">
              <avue-input-number v-model="ywData.pageNumberDigits"
                                 controls-position
                                 :precision="0"
                                 :min-rows="3"
                                 :max-rows="6">
              </avue-input-number>
              <div class="tips">注：设置{{ywData.pageNumberDigits}}位结果为 {{'000000'.substr(0,
                ywData.pageNumberDigits)}}.jpg
              </div>
            </div>
          </el-form-item>
          <!--<el-form-item label="原文存储路径：">
            <span>{{}}</span>
          </el-form-item>-->
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="header">
        <span>pdf文件类型格式转换后存储路径</span><!--原ofd-->
        <div>
          <!--<el-button size="small" icon="el-icon-edit">编辑</el-button>-->
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading2"
                     @click="handleSave(2)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="ofdData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="根路径：">
            <el-input size="small" disabled v-model="ofdData.rootPath"></el-input>
            <!--            <el-button size="small">检验</el-button>-->
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="ofdData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="子路径：">
            <el-input disabled size="small" v-model="ofdData.subPath"></el-input>
            <el-button size="small" @click="handleChange('2')">选择</el-button>
            <div class="tips">
              <span v-for="(item, index) in ofdSrcFormat"
                    :key="index">
                    {{index !== 0 ? '/' : ''}}{{item.dictLabel}}{{'-' + item.length}}
                </span>
            </div>
          </el-form-item>
          <el-form-item label="原文存储方式：">
            <el-radio-group v-model="ofdData.saveMode">
              <el-radio :label="'1'">默认文件名</el-radio>
              <el-radio :label="'2'">档号+页码</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="页码位数：" v-if="ofdData.saveMode>1">
            <div class="page-num">
              <avue-input-number v-model="ofdData.pageNumberDigits"
                                 controls-position
                                 :precision="0"
                                 :min-rows="3"
                                 :max-rows="6">
              </avue-input-number>
              <div class="tips">注：设置{{ofdData.pageNumberDigits}}位结果为 {{'000000'.substr(0,
                ofdData.pageNumberDigits)}}.jpg
              </div>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="header">
        <span>ocr识别内容存储路径</span>
        <div>
          <!--<el-button size="small" icon="el-icon-edit">编辑</el-button>-->
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading3"
                     @click="handleSave(3)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="ocrData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="根路径：" prop="root">
            <el-input size="small" disabled v-model="ocrData.rootPath"></el-input>
            <!--            <el-button size="small">检验</el-button>-->
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="ocrData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="子路径：">
            <el-input disabled size="small" v-model="ocrData.subPath"></el-input>
            <el-button size="small" @click="handleChange('3')">选择</el-button>
            <div class="tips">
              <span v-for="(item, index) in ocrSrcFormat"
                    :key="index">
                    {{index !== 0 ? '/' : ''}}{{item.dictLabel}}{{'-' + item.length}}
                </span>
            </div>
          </el-form-item>
          <el-form-item label="原文存储方式：">
            <span>默认为原文存储名</span>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="header">
        <span>文件下载时存储设置</span>
        <div>
          <!--<el-button size="small" icon="el-icon-edit">编辑</el-button>-->
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading4"
                     @click="handleSave(4)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="xzData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="根路径：">
            <el-input size="small" disabled v-model="xzData.rootPath"></el-input>
            <!--            <el-button size="small">检验</el-button>-->
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="xzData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="子路径：">
            <el-input disabled size="small" v-model="xzData.subPath"></el-input>
            <el-button size="small" @click="handleChange('4')">选择</el-button>
            <div class="tips">
              <span v-for="(item, index) in xzSrcFormat"
                    :key="index">
                    {{index !== 0 ? '/' : ''}}{{item.dictLabel}}{{'-' + item.length}}
                </span>
            </div>
          </el-form-item>
          <el-form-item label="原文存储方式：">
            <el-radio-group v-model="xzData.saveMode">
              <el-radio :label="'1'">默认文件名</el-radio>
              <el-radio :label="'2'">档号+页码</el-radio>
              <el-radio :label="'3'">页码</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="页码位数：" v-if="xzData.saveMode>1">
            <div class="page-num">
              <avue-input-number v-model="xzData.pageNumberDigits"
                                 controls-position
                                 :precision="0"
                                 :min-rows="3"
                                 :max-rows="6">
              </avue-input-number>
              <div class="tips">注：设置{{xzData.pageNumberDigits}}位结果为 {{'000000'.substr(0,
                xzData.pageNumberDigits)}}.jpg
              </div>
            </div>
          </el-form-item>
          <el-form-item label="下载压缩格式：" prop="name">
            <el-radio-group v-model="xzData.isCompress">
              <el-radio :label="true">默认不压缩</el-radio>
              <el-radio :label="false">ZIP</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="下载压缩加密：" prop="name">
            <el-radio-group v-model="xzData.isEncrypted">
              <el-radio :label="false">默认不加密</el-radio>
              <el-radio :label="true">加密</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="输入密码：" v-if="xzData.isEncrypted">
            <el-input size="small" v-model="xzData.encryptionPassword"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <!--

    <el-card class="box-card">
      <div slot="header" class="header">
        <span>水印存储路径设置</span>
        <div>
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading5"
                     @click="handleSave(5)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="syData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="默认路径：">
            <el-input size="small" v-model="syData.defaultPath"></el-input>
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="syData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="header">
        <span>电子归档章储路径设置</span>
        <div>
          <el-button type="primary"
                     size="small"
                     :loading="saveLoading6"
                     @click="handleSave(6)"
                     icon="el-icon-circle-plus-outline">保存
          </el-button>
        </div>
      </div>
      <div class="card-content">
        <el-form :model="dzData"
                 ref="ruleForm"
                 label-width="130px"
                 class="yuyi-ruleForm">
          <el-form-item label="默认路径：">
            <el-input size="small" v-model="dzData.defaultPath"></el-input>
          </el-form-item>
          <el-form-item label="桶名称：">
            <el-select size="small" v-model="dzData.bucketName">
              <el-option v-for="(item, index) in tongList"
                         :key="index"
                         :label="item"
                         :value="item"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    -->

    <el-dialog :title="dialogTitle"
               :width="dialogWidth"
               top="6vh"
               :destroy-on-close="true"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               :visible.sync="dialogShow">
      <div class="import-content">
        <sub-path-set :tableDataList="tableDataList"
                      :rowData="rowData"
                      :flog="flog"
                      @handleSave="handleSaveSubPath"></sub-path-set>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import SubPathSet from './subPathSet'
import axios from 'axios'
import { editSrcSet, getBucketName, getSrcSet } from '../../../../../api/srcSet'
import { getSysDicId } from '../../../../../api/dictionary/dictionary'

export default {
  name: 'srcSet',
  components: { SubPathSet },
  // 路径管理设置
  data () {
    return {
      loading: true,
      tongList: [], // 桶名称集合
      saveLoading1: false,
      saveLoading2: false,
      saveLoading3: false,
      saveLoading4: false,
      saveLoading5: false,
      saveLoading6: false,
      dialogTitle: '子路径设置',
      dialogWidth: '70%',
      dialogShow: false,
      flog: '',
      rowData: {},
      ywData: {}, // 原文管理
      ofdData: {}, // ofd
      ocrData: {}, // ocr
      xzData: {}, // 下载路径
      syData: {}, // 水印
      dzData: {}, // 电子
      ywSrcFormat: [], // 原文管理提示
      ofdSrcFormat: [], // ofd提示
      ocrSrcFormat: [], // ocr提示
      xzSrcFormat: [], // 下载路径提示
      tableDataList: [] // 弹窗的list
    }
  },
  mounted () {
    this.getDic()
  },
  methods: {
    getDic () {
      getBucketName().then(res => {
        this.tongList = res.data.data
      })

      this.loading = true
      const requestList = [
        getSrcSet(1),
        getSrcSet(2),
        getSrcSet(3),
        getSrcSet(4),
        // getSrcSet(5),
        // getSrcSet(6),
        getSysDicId('path_son_manage') // 获取子路径的数据字典
      ]
      axios.all(requestList).then(
        axios.spread(
          (yuanwenData, ofdData, ocrData, downloadData, /* shuiyinData, dianziData, */ diaList) => {
            this.ywData = yuanwenData.data.data
            this.ofdData = ofdData.data.data
            this.ocrData = ocrData.data.data
            this.xzData = downloadData.data.data
            // this.syData = shuiyinData.data.data
            // this.dzData = dianziData.data.data
            diaList.data.data.map((item, index) => {
              item.length = 0
              item.switch = false
              item.sort = Number(index + 1)
            })
            this.tableDataList = diaList.data.data

            this.loading = false
          }
        )
      ).catch(() => {
        this.loading = false
      })
    },
    handleChange (flog) {
      const form = {
        1: 'ywData', // 原文管理
        2: 'ofdData', // ofd
        3: 'ocrData', // ocr
        4: 'xzData', // 下载路径
        5: 'syData', // 水印
        6: 'dzData' // 电子
      }
      this.flog = flog
      this.dialogShow = true
      this.rowData = this[form[flog]]
    },
    handleSaveSubPath (srcFormat) {
      // 保存子路径
      const form = {
        1: 'ywData', // 原文管理
        2: 'ofdData', // ofd
        3: 'ocrData', // ocr
        4: 'xzData', // 下载路径
        5: 'syData', // 水印
        6: 'dzData' // 电子
      }
      const formFormat = {
        1: 'ywSrcFormat', // 原文管理
        2: 'ofdSrcFormat', // ofd
        3: 'ocrSrcFormat', // ocr
        4: 'xzSrcFormat' // 下载路径
      }
      this.dialogShow = false
      this[form[this.flog]].subPath = ''
      srcFormat.map((item, index) => {
        this[form[this.flog]].subPath += (index !== 0 ? '/{' : '{') + item.dictValue + '}'
      })
      this.$set(this, formFormat[this.flog], JSON.parse(JSON.stringify(srcFormat)))
    },
    handleSave (type) {
      // 保存
      this['saveLoading' + type] = true
      const form = {
        1: 'ywData', // 原文管理
        2: 'ofdData', // ofd
        3: 'ocrData', // ocr
        4: 'xzData', // 下载路径
        5: 'syData', // 水印
        6: 'dzData' // 电子
      }
      editSrcSet(this[form[type]]).then(() => {
        this.$message.success('保存成功！')
        this['saveLoading' + type] = false
      }).catch(() => {
        this['saveLoading' + type] = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "../../../../../styles/mixin";

  .set {
    .box-card {
      margin-top: 20px;

      &:first-child {
        margin-top: 0;
      }

      .header {
        @include fj;
        align-items: center;
      }

      ::v-deep .el-card__header {
        padding: 10px 20px;
      }

      ::v-deep .el-input {
        width: 350px;
        margin-right: 10px;
      }

      .tips {
        @include sc(12px, #999);
        line-height: normal;
      }

      .page-num {
        ::v-deep .el-input {
          width: 182px;
          margin-right: 10px;
        }
      }
    }
  }
</style>
